import { ActivityModel } from '../models/activity.js';

export const ActivityController = {
  async getAllActivities(req, res) {
    try {
      const activities = await ActivityModel.getAllActivities();
      res.json(activities);
    } catch (error) {
      res.status(500).json({ error: 'Failed to fetch activities' });
    }
  },

  async createActivity(req, res) {
    try {
      const id = await ActivityModel.createActivity(req.body);
      res.status(201).json({ id, ...req.body });
    } catch (error) {
      res.status(500).json({ error: 'Failed to create activity' });
    }
  },

  async updateActivity(req, res) {
    try {
      const success = await ActivityModel.updateActivity(req.params.id, req.body);
      if (success) {
        res.json({ id: req.params.id, ...req.body });
      } else {
        res.status(404).json({ error: 'Activity not found' });
      }
    } catch (error) {
      res.status(500).json({ error: 'Failed to update activity' });
    }
  }
};